/*十字路分为横向路Hroad和纵向路Vroad；
Hroad和Vroad交替通行，每条路的绿灯保持一段时间（30秒）才通过黄灯（3秒）变为红灯，同时另一条路的交通灯从红灯变为绿灯；
使用板载的LED灯代表交通灯上的红、黄、绿灯，两块数码管分别显示两条路上的绿灯和红灯最后15秒倒计时和黄灯3秒倒计时；*/

module traffic_top(
    input clk,
    input reset,   
    output H_light_green,
    output H_light_yellow,
    output H_light_red,
    output V_light_green,
    output V_light_yellow,
    output V_light_red,
    output [3:0] an,
    output [7:0] sseg  
   // output [7:0] counter
    
    );
    
    wire clk_200;
    wire clk_1;
    clkdiv U1(
        .clk(clk),.clr(reset),.clk_200Hz(clk_200),.clk_1Hz(clk_1)
            );
            
    wire Start_timer_33;
    wire [7:0] counter_33;   
    
    counter U2(
        .clk(clk_1),.clr(reset),.Start_timer_33(Start_timer_33),.q(counter_33)
            );
            
    wire [1:0] H_display_en;     
    wire [1:0] V_display_en;     
    wire [3:0] H_count;     
    wire [3:0] V_count;     
    
    traffic U3 (
        .clk_1(clk_1),
        .reset(reset),
        .counter_33(counter_33),
        .Start_timer_33(Start_timer_33),
        .H_display_en(H_display_en),
        .H_count(H_count),
        .V_display_en(V_display_en),
        .V_count(V_count),
        .H_light_green(H_light_green),
        .H_light_yellow(H_light_yellow),
        .H_light_red(H_light_red),
        .V_light_green(V_light_green),
        .V_light_yellow(V_light_yellow),
        .V_light_red(V_light_red)
    );
        
    wire [7:0] H_bcd;
    wire [7:0] V_bcd;
    bin_2_bcd U4(
        .data_bin(H_count),
        .data_bcd(H_bcd)
        );  
            
    bin_2_bcd U5(
        .data_bin(V_count),
        .data_bcd(V_bcd)
        );              
    bin_2_bcd U6(
        .data_bin(counter_33),
        .data_bcd(counter)
        );  
    display U7(
        .clk_200(clk_200),
        .hex3(H_bcd[7:4]),
        .hex2(H_bcd[3:0]),
        .hex1(V_bcd[7:4]),
        .hex0(V_bcd[3:0]),
        .display_en({H_display_en,V_display_en}),    
        .an(an),
        .sseg(sseg)
    );                     
                  
endmodule